package com.CmJava.sqlSessionFactoryBuilder;

import com.CmJava.sqlSessionFactoryBuilder.sqlSessionFactory.SqlSessionFactory;
import com.CmJava.sqlSessionFactoryBuilder.sqlSessionFactory.configuration.Configuration;
import com.CmJava.sqlSessionFactoryBuilder.xml.XMLConfigBuilder;

import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public SqlSessionFactoryBuilder() {
    }

    public SqlSessionFactory build(InputStream inputStream) {

        //实现自己的XMLConfigBuilder，解析mybatis-config.xml
        //这里其实也是用了dom4j这个包的api，简化了书写
        XMLConfigBuilder parser = new XMLConfigBuilder(inputStream);
        SqlSessionFactory sqlSessionFactory = this.build(parser.parse());
        return sqlSessionFactory;

    }

    ;

    public SqlSessionFactory build(Configuration config) {
        return new SqlSessionFactory(config);
    }
}
